package com.zhangx.datastructure.stacklist;

import java.util.Arrays;

/**
 * @ClassName LinearStack
 * @Description TODO
 * @Author zhangx
 * @Date 2020/12/30 8:47
 **/
public class LinearStack {
    private int MAX_SIZE = 10;
    private int[] data = new int[10];
    private int top = -1;

    void push(int item){
        data[++top] = item;
    }

    int pop(){
        int d = data[top];
        data[top] = 0;
        top--;
        return d;
    }

    @Override
    public String toString() {
        return "LinearStack{" +
                "MAX_SIZE=" + MAX_SIZE +
                ", data=" + Arrays.toString(data) +
                ", top=" + top +
                '}';
    }

    public static void main(String[] args) {
        LinearStack linearStack = new LinearStack();
        linearStack.push(9);
        System.out.println(linearStack);
        linearStack.push(8);
        System.out.println(linearStack);

        int item = linearStack.pop();
        System.out.println("出栈元素="+item);
        System.out.println(linearStack);
    }




}
